<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>通行证管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
    <link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}admin.css" type="text/css">
    <script type="text/javascript" src="{$url_js}jquery-1.12.0.min.js"></script>
    {literal}
        <style>
            .tag-box a{color: #333}
            .tag-box,.tag-box2{min-width: 600px;text-align: center;}
            .tag-box p,.tag-box2 p{padding: 0; margin: 0;}
            .tag-box a,.tag-box2 a{padding: 0 3px;margin: 0 2px;text-decoration: none;}
        </style>
    {/literal}
</head>
<body>

<div class="container" style="width:96%">
    <form action="">
        <table class="table table-bordered table-striped" align="center">
            <tbody>
            <tr><td colspan="4"><h5>通行证查询</h5></td></tr>
            <tr>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <div class="input-group-addon">用户ID</div>
                        <input type="text" class="form-control" id="search_id"  value="" placeholder="用户ID" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" />
                    </div>
                </td>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <div class="input-group-addon">用户手机号：</div>
                        <input type="text" class="form-control" id="search_mobile" value="" placeholder="用户手机号" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" maxlength="11" />
                    </div>
                </td>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <div class="input-group-addon">用户名：</div>
                        <input type="text" class="form-control" id="search_name" value="" placeholder="用户登录名" />
                    </div>
                </td>
                <td class="form-group col-xs-2">
                    <div class="input-group">
                        <input type="button" id="search_btn" class="btn btn-primary" value="精确查询用户" />&nbsp;
                        <input type="reset" class="btn btn-warning" value="重置条件" />
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>

<div class="container" style="width:96%; margin-top: 10px; display: none" id = "user_one">

    <form action="" class="form-inline">
        <table class="table table-bordered table-striped" align="center">
            <tbody>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户ID：</td>
                    <td class="col-xs-3" id="user_id"></td>
                    </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户登录名：</td>
                    <td class="col-xs-3" id="user_name"></td>
                    </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户昵称：</td>
                    <td class="col-xs-3" id="user_nick"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户头像：</td>
                    <td class="col-xs-3" ><img src="" id="avatar"/></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">重设用户密码：</td>
                    <td>
                        <div class="form-group">
                            <input type="password" class="form-control" id="password" placeholder="重置用户密码" autocomplete="off"/>
                        </div>
                        <input type="button" class="btn btn-default" id="update_pwd_btn" value="修改密码"/>
                    </td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户手机号：</td>
                    <td class="col-xs-3" id="mobile"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">真实姓名：</td>
                    <td class="col-xs-3" id="real_name"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户性别：</td>
                    <td class="col-xs-3" id="gender"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户生日：</td>
                    <td class="col-xs-3" id="birthday"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">用户签名：</td>
                    <td class="col-xs-3" id="sign"></td>
                </tr>
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">文章收藏数量：</td>*}
                    {*<td class="col-xs-3" id="favorite_count"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">我的文章数量：</td>*}
                    {*<td class="col-xs-3" id="article_count"></td>*}
                {*</tr>*}
                <tr>
                    <td class="col-xs-2" style="width: 8%">注册时间：</td>
                    <td class="col-xs-3" id="create_time"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">最后登录的时间：</td>
                    <td class="col-xs-3" id="login_time"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">登录计数：</td>
                    <td class="col-xs-3" id="login_count"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">邀请码：</td>
                    <td class="col-xs-3" id="invitation"></td>
                </tr>
                <tr>
                    <td class="col-xs-2" style="width: 8%">现有金果数：</td>
                    <td class="col-xs-3" id="existing_gold"></td>
                </tr>
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">为上级进贡金币数：</td>*}
                    {*<td class="col-xs-3" id="tribute"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">为上级的上级进贡金币数：</td>*}
                    {*<td class="col-xs-3" id="parent_tribute"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">累计获取现有金币数：</td>*}
                    {*<td class="col-xs-3" id="cumulative_gold"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">现金数：</td>*}
                    {*<td class="col-xs-3" id="existing_cash"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">累计获取现金数：</td>*}
                    {*<td class="col-xs-3" id="cumulative_cash"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">为上级用户累计获取活跃金币数：</td>*}
                    {*<td class="col-xs-3" id="active_gold"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">为上级用户累计获取邀请现金数：</td>*}
                    {*<td class="col-xs-3" id="invitation_cash"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">已签到累计：</td>*}
                    {*<td class="col-xs-3" id="cumulative_sign"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">上次签到日期：</td>*}
                    {*<td class="col-xs-3" id="sign_time"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%" id="userStatus">用户状态：</td>*}
                    {*<td class="col-xs-3" id="user_status"></td>*}
                {*</tr>*}
                {*<tr>*}
                    {*<td class="col-xs-2" style="width: 8%">我的频道：</td>*}
                    {*<td class="col-xs-3" id="my_channel"></td>*}
                {*</tr>*}
            </tbody>
        </table>
    </form>
</div>
{literal}
    <script type="text/javascript">
        var account = {
            'search_id' : $("#search_id"),
            'search_mobile' : $("#search_mobile"),
            'search_name' : $("#search_name"),

            'user_id' : $("#user_id"),
            'password' : $("#password"),
            'user_name' : $("#user_name"),
            'email' : $("#email"),
            'mobile' : $("#mobile"),
            'user_nick' : $("#user_nick"),
            'real_name' : $("#real_name"),
            'gender' : $("#gender"),
            'avatar' : $("#avatar"),
            'birthday' : $("#birthday"),
            'login_count' : $("#login_count"),
            'login_time' : $("#login_time"),
            'create_time' : $("#create_time"),
            'user_status' : $("#user_status"),

            // 手机验证
            checkMobile : function (mobile){
                var reg = /^\d{11}$/;
                if (!reg.test(mobile))
                    return false;
                else
                    return true;
            },

            // 查询成功，显示相关数据
            setData : function (data){
                this.search_id.val(data.UserId);
                this.search_mobile.val(data.LoginMobile);
                this.search_name.val(data.LoginName);

                this.user_id.html(data.UserId);
                this.user_name.html(data.LoginName);
                this.email.html(data.Email);
                this.mobile.html(data.LoginMobile);
                this.user_nick.html(data.UserNick);
                this.real_name.html(data.RealName);
                this.gender.html(data.Gender);
                this.avatar.attr('src',data.Avatar);
                this.birthday.html(data.Birthday);
                this.login_count.html(data.LoginCount);
                this.login_time.html(data.LoginTime);
                this.create_time.html(data.CreateTime);
                this.user_status.html(data.Status);
            },

            // 修改数据
            updateData : function (url, param){
                if (!param.user_id){
                    top.swal('出错了', '用户ID不能为空！', 'error');
                    return false;
                }
                if ('undefined' !== typeof param.password && !param.password.length){
                    top.swal('出错了', '重设用户密码不能为空！', 'error');
                    return false;
                }
                if (param.password.length < 6) {
                    top.swal('出错了', '密码长度不能小于6位', 'error');
                    return false;
                }
                if (param.password.length > 20) {
                    top.swal('出错了', '密码长度不能大于20位', 'error');
                    return false;
                }

                $.post(url, param, function (data){
                    if (typeof data == 'string')
                        data = eval("("+data+")");
                    if (data.status){
                        top.swal(data.msg, '', 'success');
                    }else{
                        top.swal(data.msg, '', 'error');
                    }
                });
            }
        };

        // 精确查询请求
        $("#search_btn").click(function(){
            var email = $.trim($("#search_email").val()),
                    user_id = $("#search_id").val(),
                    mobile = $.trim($("#search_mobile").val()),
                    name = $.trim($("#search_name").val());

            if (email == '' &&  mobile == '' && user_id == '' && name == ''){
                top.swal('出错了', '参数不能全部为空！', 'error');
                return false;
            }
            if (mobile != '' && !account.checkMobile(mobile)){
                top.swal('出错了', '手机格式不合法！', 'error');
                return false;
            }

            $.post('?do=search', {'email' : email, 'user_id' : user_id, 'mobile' : mobile, 'name': name}, function(data) {
                if (typeof data == 'string')
                    data = eval("("+data+")");

                if (data.status){
                    account.setData(data.data);
                    $("#user_one").css("display","");
                    if (data.data.UserType == '未填写') {
                        $("#user_two").css("display", "none");
                    } else {
                        $("#user_two").css("display", "");
                    }
                }else{
                    top.swal('出错了', data.msg, 'error');

                }
            });
        });

        // 修改密码
        $("#update_pwd_btn").click(function(){
            var password = $.trim(account.password.val()), user_id = account.user_id.html();
            account.updateData('?do=Update', {'user_id' : user_id, 'password' : password});
            $("#password").val("");
        });
    </script>
{/literal}
</body>
</html>